<template>
	<z-paging ref="paging" v-model="dataList" @query="queryList"
		empty-view-img="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/12/987eadb1d50949a0a7e25dbbd99abe30.png"
		empty-view-text="暂无内容" auto-scroll-to-top-when-reload>
		<view slot="top" class="title">
			<view class="title_left">
				<view class="title_left_line"></view>
				<text class="title_left_text">所有客户服务</text>
			</view>
			<text class="title_rightText">最近一月</text>
		</view>

		<view class="salesItem" v-for="item in dataList" :key="item.userId" @click="to_serviceDetail(item)">
			<u-image width="84rpx" height="84rpx" :src="imageType[item.type].image" mode="aspectFill" />

			<view class="salesItem_content">
				<view class="salesItem_content_top flex_wrap">
					<view>
						<u-text size="36rpx" color="#3D3D3D" :text="item.personServed"></u-text>
					</view>
					<view style="margin-left: 20rpx">
						<u-text size="24rpx" color="#333333" :text="'服务人：' + item.servicer"></u-text>
					</view>
				</view>
				<view>
					<u-text size="28rpx" color="#666666" :text="
              '服务时间：' + $u.timeFormat(item.serviceTime, 'yyyy年mm月dd日')
            "></u-text>
				</view>
			</view>
			<u-button type="primary" shape="circle" :hairline="false" color="#EAF2FF"
				:customStyle="buttonCustomStyle">{{ imageType[item.type].text }}</u-button>
		</view>
	</z-paging>
</template>

<script>
	import {
		toHealthForServiceLog
	} from "@/api/statistics";

	export default {
		data() {
			return {
				beginTime: '',
				endTime: '',
				dataList: [],
				imageType: {
					1: {
						text: "电话",
						image: "https://test-health-s.oss-cn-hangzhou.aliyuncs.com/2023/09/22/cbe9dc3ba12b474da2ad52851fe2c76c.png",
					},
					2: {
						text: "邮箱",
						image: "https://test-health-s.oss-cn-hangzhou.aliyuncs.com/2023/09/22/efc352c5c36947d28b90b30f0e3f76c2.png",
					},
					3: {
						text: "上门",
						image: "https://test-health-s.oss-cn-hangzhou.aliyuncs.com/2023/09/22/8f32e789ec1941aea87e199875fa3ba4.png",
					},
					4: {
						text: "微信",
						image: "https://test-health-s.oss-cn-hangzhou.aliyuncs.com/2023/09/22/0e09cd10ef83468197da76c04e648489.png",
					},
				},
				buttonCustomStyle: {
					width: "140rpx",
					height: "58rpx",
					fontSize: "32rpx",
					color: "#588BF3",
					margin: "0",
				},
			};
		},
		methods: {
			getParamsTime() {
				let now = new Date()
				this.endTime = uni.$u.timeFormat(now, 'yyyy-mm-dd hh:MM:ss');
				// 当前月的日期
				let nowDate = now.getDate();
				let lastMonth = new Date(now.getTime());
				// 设置上一个月（这里不需要减1）
				lastMonth.setMonth(lastMonth.getMonth());
				// 设置为0，默认为当前月的最后一天
				lastMonth.setDate(0);
				// 上一个月的天数
				let daysOflastMonth = lastMonth.getDate();
				// 设置上一个月的日期，如果当前月的日期大于上个月的总天数，则为最后一天
				this.startTime = new Date(lastMonth.setDate(nowDate > daysOflastMonth ? daysOflastMonth : nowDate))
				this.beginTime = uni.$u.timeFormat(this.startTime, 'yyyy-mm-dd hh:MM:ss');
			},
			to_serviceDetail(item) {
				const data = JSON.stringify(item);
				this.$u.route({
					url: "/pages_my/user_manage/serviceList/detail",
					params: {
						data,
					},
				});
			},
			async queryList(pageNum, pageSize) {
				this.getParamsTime()
				toHealthForServiceLog({
						pageNum,
						pageSize,
						endTime: this.endTime,
						beginTime: this.beginTime,
					})
					.then((res) => {
						this.$refs.paging.complete(res.data.rows);
					})
					.catch(() => {
						this.$refs.paging.complete(false);
					});
			},
		},
	};
</script>

<style>
	page {
		background: #f6f9ff;
	}
</style>

<style lang="scss" scoped>
	.title {
		width: 100%;
		padding: 30rpx 40rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;

		&_rightText {
			font-size: 24rpx;
			color: #588bf3;
		}

		&_left {
			display: flex;
			align-items: center;

			&_line {
				width: 8rpx;
				height: 28rpx;
				border-radius: 200rpx;
				background-color: #588bf3;
				margin-right: 20rpx;
			}

			&_text {
				font-weight: bold;
				color: #333;
				font-size: 28rpx;
			}
		}
	}

	.salesItem {
		width: 668rpx;
		min-height: 168rpx;
		background: #fff;
		border-radius: 20rpx;
		margin: 0 auto;
		display: flex;
		margin-bottom: 40rpx;
		justify-content: space-between;
		align-items: center;
		padding: 0 28rpx;
		box-sizing: border-box;

		&_content {
			display: flex;
			flex-direction: column;

			&_top {
				align-items: baseline;
			}
		}
	}
</style>
